﻿using MediatR;
using W.Warehouse.Api.Application.Command.OutboundCommand;
using W.Warehouse.Repository.Impl;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.OutboundCommandHadler
{
    public class OutboundDeleteCommandHandler : IRequestHandler<OutboundDeleteCommand, int>
    {
        private readonly IOutboundRepository outboundRepository;

        private readonly IOutStorageProductsRepository outStorageProductsRepository;

        public OutboundDeleteCommandHandler(IOutboundRepository outboundRepository, IOutStorageProductsRepository outStorageProductsRepository)
        {
            this.outboundRepository = outboundRepository;
            this.outStorageProductsRepository = outStorageProductsRepository;
        }

        public async Task<int> Handle(OutboundDeleteCommand request, CancellationToken cancellationToken)
        {
            var row = 0;
            var list = await outboundRepository.GetAsync(w => w.Outboundid == request.Outboundid);
            list.FirstOrDefault().IsDelete= true;
            list.FirstOrDefault().DeleteTime= DateTime.Now;
            return await outboundRepository.UpdateAsync(list.FirstOrDefault());
        }
    }
}
